@extends('layouts.app')
@section('description',$topic->excerpt)
@section('title',$topic->title.'的详情页')

@section('content')
    <div class="row">
        <div class="col-md-3 mb-2 d-none d-md-block">
            <div class="card">
                <div class="card-body">
                    <h5 class="text-center pt-2">作者:
                        <a class="text-decoration-none text-success" href="{{route('users.show',$topic->user_id)}}">{{$topic->user->name}}</a>
                    </h5>
                    <img alt="{{$topic->user->name}}" src="{{$topic->user->avatar}}" class="img-thumbnail border-0 rounded"/>
                </div>
            </div>
        </div>
        <div class="col-md-9">
            <div class="card mb-2">
                <div class="card-body">
                    <h4 class="text-center">{{$topic->title}}</h4>
                    <small class="text-secondary d-flex justify-content-center">
                        <span>{{$topic->created_at->diffForHumans()}}</span>
                        <span>&nbsp;•&nbsp;</span>
                        <span>
                            <i class="fa-regular fa-comment"></i>
                            <span>{{$topic->reply_count}}</span>
                        </span>
                        <span>&nbsp;•&nbsp;</span>
                        <span>
                            <i class="fa-regular fa-folder-closed "></i>
                            <a class="text-secondary text-decoration-none" href="{{route('categories.show',$topic->category_id)}}">{{$topic->category->name}}</a>
                        </span>
                    </small>
                    <div class="py-4 d-flex justify-content-center">
                            <a href="{{route('topics.create')}}"  class="btn btn-outline-success btn-sm">
                                <i class="fa-solid fa-circle-plus "></i>
                                发帖
                            </a>
                        @can('update',$topic)
                            <a  href="{{route('topics.edit',$topic->id)}}" class="btn btn-outline-warning btn-sm mx-2">
                                <i class="fa-regular fa-pen-to-square"></i>
                                编辑
                            </a>
                            <form action="{{route('topics.destroy',$topic->id)}}" method="POST"
                            onclick="return confirm('你确认要删除该帖子吗？')"
                            >
                                @csrf
                                {{method_field('DELETE')}}
                                <button type="submit" class="btn btn-outline-danger btn-sm">
                                    <i class="fa-regular fa-trash-can "></i>
                                    删除
                                </button>
                            </form>
                            @endcan
                    </div>
                    <div class="topic-body mt-2">
                       {!!  $topic->body !!}
                    </div>
                </div>
            </div>
            <div class="card mt-2">
                <div class="card-body">
                   @includeWhen(Auth::check(),'topics._reply_box',['topic'=>$topic])
                   @include('topics._reply_list',['replies'=>$topic->replies()->recent()->with('user','topic')->get()])
                </div>
            </div>
        </div>
    </div>
@stop


